// pages/feedback/feedback.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     content:0,
     textarea:"亲爱的，您的每一个意见都是我们对产品优化的方向和动力。快来写下你的意见吧"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  textareChange(e){
    this.setData({
      content: e.detail.value
    })
 },
  formSubmit: function (e) {
    console.log("获取e.detail.url", e.detail.formId)
    var formId = e.detail.formId

    var that = this
    console.log("获取form_id", this.data.content)
    if (that.data.content != "亲爱的，您的每一个意见都是我们对产品优化的方向和动力。快来写下你的意见吧" && that.data.content != 0) {
      wx.request({
        url: app.urlData.getURL + '/index.php/api/SApi/index/key/' + app.urlData.key + '/m/add_formid/wid/' + app.urlData.wid + '/sign/' + wx.getStorageSync('sign'),
        method: 'GET',
        data: {
          type: 3,
          form_id: formId,
          user_id: wx.getStorageSync('ydn_id'),
        },
        success: (res) => {
          console.log(res)
        }
      })
    }
  },
 start(e){
  let contents = this.data.textarea;
   if (contents === "亲爱的，您的每一个意见都是我们对产品优化的方向和动力。快来写下你的意见吧"){
     this.setData({
       textarea:""
     })
   }
 },
  submitcontent(){
    var that = this;
    // content = this.data.content
    console.log('请输入内容哦', this.data.content)
    if (this.data.content == ""){
      wx.showToast({
        title: '请输入内容',
        icon:"none",
        success: function () {
          setTimeout(function () {
            // wx.navigateBack({})
          }, 1500)
        },
      })
    }else{
    wx.request({
      // url: app.url+'/index.php/mobile/Shopindex/feedback',
      url: app.urlData.getURL + '/index.php/api/SApi/index/key/' + app.urlData.key + '/m/feedback/wid/' + app.urlData.wid + '/sign/' + wx.getStorageSync('sign'),
      data: {
        content: this.data.content
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        wx.showToast({
          title: '您的反馈已提交成功',
          success: function () {
            setTimeout(function () {
              wx.navigateBack({})
            }, 1000)
          },
        })
      }
    })
    }
  }
})
